package cn.gwm.flink.streaming.dwm.charge.template;

import cn.gwm.flink.streaming.constant.BaseFields;
import cn.gwm.flink.streaming.dwm.charge.bean.ChargeArgs;
import cn.hutool.json.JSONObject;
import org.apache.flink.api.common.state.ValueState;

/**
 * @ClassName FaultChargeState
 * @Description 故障
 * @Author LiangGuang
 * @Date 2023/05/11 18:04
 */
public class FaultChargeState extends ChargeStateModel {
    @Override
    protected void stateStartSelfHandle(ChargeArgs args) throws Exception {
        Long breakTime = args.getChargeBreakState().value();
        if (breakTime == null) {
            args.getChargeBreakState().update(args.getFirstData().getLong(BaseFields.tid));
        }
        // 设置充电失败
        ValueState<JSONObject> summarState = args.getSummarState();
        ValueState<JSONObject> bandSummarState = args.getBandSummarState();
        summarState.update(summarState.value().set("chargeSuccOrFail", 0));
        summarState.update(summarState.value().set("faultCode", args.getFirstData().getStr(args.getConstant().getFaultCode())));
        bandSummarState.update(bandSummarState.value().set("chargeSuccOrFail", 0));
        bandSummarState.update(bandSummarState.value().set("faultCode", args.getFirstData().getStr(args.getConstant().getFaultCode())));

    }

    @Override
    protected void stateEndSelfHandle(ChargeArgs args) throws Exception {

    }
}
